// 分类数据模型
module.exports = class Article extends require("./model") {
    /**
     * 获取分类
     */
    static getList() {
      return new Promise((resolve, reject) => {
        let sql = 'SELECT id,`name` FROM category ORDER BY "index" DESC';
        this.query(sql).then(res => {
          resolve(res)
        }).catch(err => {
          console.log(` 获取分类失败：${err.message}`);
          reject(err)
        })
      })
    }
    /**
     * 获取指定分类
     * @param {integer} id 分类编号
     */
    static getCategoryId(id) {
      return new Promise((resolve, reject) => {
        let sql = 'SELECT id,`name`,`index` FROM category WHERE id = ?';
        this.query(sql,id).then(res => {
          resolve(res)
        }).catch(err => {
          console.log(` 获取分类失败：${err.message}`);
          reject(err)
        })
      })
    }
  };